/*
 * @Author: Lijin
 * @Date: 2024-09-19 13:56:33
 * @LastEditors: Lijin
 * @LastEditTime: 2024-09-23 10:12:30
 * @FilePath: \huawei-flash-sale\join1.js
 * @Description:
 *
 * Copyright (c) 2024 by 18323406700, All Rights Reserved.
 */
const axios = require("axios");
const moment = require("moment");

const activityID = 249933;

const orders = 2601010506012;

const Cookie = [
  "euid=8276b5c3576916b14a3cbc2edbe521ad539f994721c6ea41; hasSigned=0; isFirstLogin=0; aliToken=; isGroupUser=false; ageGroupFlag=0; optBanding=0; weChatInfo=false; ac_loNa=191****4001; ac_lel=; ac_lmi=; ac_lus=1; ac_lgc=0; ac_ltp=0; ac_li=true; isVpro=0; ac_cp=1500721829297|1500721912154|1599634375481; rush_info=30086000813131912_1727054409_SEC7CD4C34CD54ED01A46599FC7F7D9E4EED42273D749295E4FC8EB12460FC520CD; rush_ext=30086000813131912_1_0_1727054409_SECAAC89921CE0040E3F98649A64AA1C03B953DE3E606EEFD7FE48CE8D05F232568; user=191****4001; hasphone=1; displayName=h**********; grouptags=99211|102014; deviceid=b0f701d273fa474be07bbc776afc3bf3; TID=b0f701d273fa474be07bbc776afc3bf3; HWWAFSESID=f320388cc1b672e3c5; HWWAFSESTIME=1727054412078; callAB=1; recommendflag=true; sdevid=39489999ddc997ebdb343d45734565c10c919803; device_data=*2k94MMPYMYImTGzWG0CjDzjPMPkMZZZLIZ4JUMUaY3W1zm2mFlHLylXyT5TxJMQ1cINAU40MFzzmz3MbNNOOAQZNQNahz32pk91k502wXzNuThh4m4xlZYZNMOAYZZVRYNQoMNBFNYVxNVEUNR4xMMgYDzjyD2k1Wm9hmTpljjsyFWlwjmyxn3yxTW1mW1xNJMMYMdNYZTbMMNSMMJJMMMNWmzm2zwzG1iYPaIAMMwcNYJVmzTTXmSSmTW3CCjykmjTD2z2jcMZEAMNQUOZEJcMZZZMgAYcp4MLUkdNUBbMkjjmTzm5zT562jwvjWlliCHDCWmmDzm1T2zmTlNOd0UYZcwMVYZ1B4UUUZd0AVJ9w3mDm1Dm0vDNBMOcQMZIAYbEl3ix9il9lmshlyppv1mo9wz0iQJYNFVZMIUMZcZNO5NNM5xcbIMMNBtMQNJLcz3yH54TjwwWmNG3D22kyylHjhunnxwWDiijWbDVNYYMcNMdYMabdQYMaMbJaNYZwGzz52D4wm2PUMdMZEdOlEZjTjWT2m2CTzWSmCVjjzWDCTjmENQYadIQMYNYMYJAMcMJNY9UbKRIacdhTbBAY0TGllTT05DS9pTjyzHCzy2WxlzVywTzw9jjxq7INEFQBAZQ1g4JdgBUkcREkdA9WD3mTj55jCpdNMIYIyum20hwBrl95WYJPIXFMQYYTFbBZRMBz9HlGuGOiyGlkpnwzmFMYNNbJJMZbcOEin4zkdF0=; uid=; CSRF-TOKEN=ShHBaadnKbXWatSWs2ndRaOwk8qb3DPvPVTh",

  "deviceid=9f9239c6df433d40a5d818ad566f8103; TID=9f9239c6df433d40a5d818ad566f8103; callAB=1; cartId=a671a74b8e744cd2abdf360c9533d8d5; HWWAFSESTIME=1727054603839; HWWAFSESID=74215b89cf422d3bba; hasSigned=0; aliToken=; isGroupUser=false; ageGroupFlag=-1; optBanding=0; weChatInfo=false; ac_loNa=132****4342; ac_lel=; ac_lmi=; ac_lus=1; ac_lgc=0; ac_ltp=0; ac_li=true; isVpro=0; ac_cp=1500721829297|1500721912154|1599634375481; user=132****4342; hasphone=1; isAuthCust=false; isAuthByUid=true; sdevid=39489999ddc997ebdb343d45734565c10c919803; device_data=*2k94JL4aQNNTGWjTXTjCnjWPhdkMVMUPZZFYQMYaJj2T9mumXTw0pTnm92mlVJOMZOaMMJMMIDxWm3JIMaZZMNdJMZ92zwyl504wmlhxwuU4wjw3imblOMUJMOAMMZNQZPRROZIBMb5xRTAINMcBJJI5zTxwTHziTWvlmCkC2XXoU2ww2WGljXym2jzx2Jl00JIZEY0UQ4UlBwtFM1gwcJVkWD2ijj0jTNJ4ZYkgZZAQbaTTDDGjTDTDmWljkkTXCWDzWWjINNIAYNEUPaQgZPMAZZEcbd9UJMQQaMMIbL9kGD34mWy2Smj9C3wuTWll22umTT0XiC59TjxoiOJJMNMONZZOJMJJSRJJJMdOZE04mmh1zTwmLJ55MMNVOYF9Ehzl2l0m6zhsszlLsyG4zzimimMBMMNNMORJOZFMMM9ENMZlYTUdJNIJMMVhMYzxXTmmWD4wGH6uTClpXzlw2jp2jTzzDTw5zj4SYYZQNQYEMMNNh4BY8AR1cElETGhzzn50Tm2MRZVAYPAIYYITzzzGVDjDGDUjWjGTTjTTTWjqEZNAab1UNJ9YYNgcOdEVOY1BdM5NVQVATaI4U21sXX01GT4mUWywj04lzjllTT3umi9xnjzxTFmNZNObaMZONePbMZMQMMJMJNYmWD4xmT00DWIcZMAN2hikuuywjwz10MJcMdMZYZVP5aIbhJIGmSimuSlj1WGTwWwT4YQIgBUEIQ1A0Yzmwz1WdF0=; euid=60a114689bb5536947dd3c38ad4d17b24bfa4c8615e41975; CSRF-TOKEN=B3001EED32D06217DCA67672B5A771D92D76A7AF63464488C240D0EFE1614F0B; isFirstLogin=0; rush_info=30086000608594364_1727056900_SEC2308B984082E6050D18980C772CC4204BABB4C68CEB57FF198FA73783D591683; rush_ext=30086000608594364_1_0_1727056900_SEC40566373D9D3F6756E4AD4AD33EBC8FFEB5C6BD8095A1AF321F81DE5B1CDD27D; uid=30086000608594364; displayName=1**********; recommendflag=true",
  "hasSigned=0; isFirstLogin=0; aliToken=; isGroupUser=false; ageGroupFlag=0; optBanding=0; weChatInfo=false; ac_loNa=191****4001; ac_lel=; ac_lmi=; ac_lus=1; ac_lgc=0; ac_ltp=0; ac_li=true; isVpro=0; ac_cp=1500721829297|1500721912154|1599634375481; user=191****4001; hasphone=1; deviceid=b0f701d273fa474be07bbc776afc3bf3; TID=b0f701d273fa474be07bbc776afc3bf3; HWWAFSESID=f320388cc1b672e3c5; HWWAFSESTIME=1727054412078; callAB=1; sdevid=39489999ddc997ebdb343d45734565c10c919803; cartId=b26f3412d3c6423d9a376599177da917; device_data=*2k94MYaANhZjTmST3CymTD2QaIMNMJOMN9bRadTBDjjkW9mpjsFljynyD19JMMNZbMSMJMEin4zkLMNNMOcJYZZJEz32xkiy95m2hXyNpT1hoi3gWYJJNPVIMXUFZMZkNYNYMTxFbbMBNZtRQMJ3jWm1Tz5mT26mjFvlWHlLCyDlWXmyzT35WTm4tM0QY1cckIYN1A4UU4Z00MZNWD3mTj55jCpAMPMMPMAkNMQjmjTTGmzCWzGS0CCjjzDDjDl0NMYgdMQQYOYEYcAZcZJgYYUpKMIUcdhUbbizzyy22T1wmWhNT3l2jkyyWHwhmnxx3W5iW1fVNYMMYNddYMTbMQNMMMJJNMTwGzy52D4wmBYdbNNMNVYYYyhu3mp290kh0wwBzrulh9liqlQYYNFOZYIZMRcNNo5NNF5YcxIVMUBRMxNMD0jGTlmTz55S2pwjjzlCiyHWClmVDwmDz2hm1IdEUQZAwQVgZJBgUUUcdE0Epw3mDm1Dm0vYkUPdIZbOMFYTmWT2X2STmWWmCVjjkWjCDj3PcMZPAkNMUZZZJZMLZIMZA4cJ4ULMkUNaBY2z39HH4ljGwumGGODi2yyGlljkupnnw32mxRcMNYYNcNMbYJaJdMYZabbcZMXWmzm2zwzG1cBOJMtli9llslpvmnvZZMAZVYQMBNVNEN4MgTlT0D9TyHz2xzyTyjtNFBZ14dBkRkEzzmz3XQ==; euid=e8115520c07eeadc2f488de60dd7ebe494408a51335cd8e1; CSRF-TOKEN=BD252A1528E1E85F2526176D4922A9B505098FA56B4268F03C7E28B1BA59F397; rush_info=30086000813131912_1727056934_SECAB2DFEE1B02EFB4ACC7EFC5607C1445F2477E8F2F77EDF08E7D37E0546BDB382; rush_ext=30086000813131912_1_0_1727056934_SEC40A0700C9E301DA3FC1B52B94BD28FE1B1E08EA5258A25FC153C401FA449571B; uid=30086000813131912; displayName=h**********; recommendflag=1; grouptags=99211|102014",
];

const init = () => {
  for (let i = 0; i < Cookie.length; i++) {
    axios({
      method: "get",
      url: `https://buy.vmall.com/joinQueue.json?activityID=${activityID}&sbomCode=${orders}&num=1&portal=1`,
      headers: {
        Accept: "application/json",
        "Accept-Encoding": "gzip, deflate, br, zstd",
        "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
        "Cache-Control": "no-store",
        Connection: "keep-alive",
        Cookie: Cookie[i],
        Origin: "https://www.vmall.com",
        Pragma: "no-cache",
        Referer: "https://www.vmall.com/",
        "Sec-Fetch-Dest": "empty",
        "Sec-Fetch-Mode": "cors",
        "Sec-Fetch-Site": "same-site",
        "User-Agent":
          "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36",
        "X-E2E-Trace":
          "e2eId=page#rn_product#1#02b6151906d4e9fba7840a939bdaa876;spanId=d259261f6f8d3230a5df626b3aa0ee47",
        "sec-ch-ua":
          '"Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128"',
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-platform": '"Windows"',
      },
    })
      .then((res) => {
        //返回的数据乱码
        // console.log(res);
        console.log(`当前id:${orders}`, JSON.stringify(res.data));

        console.log("----------------------- 当前时间戳", new Date().getTime());

        setInterval(() => {
          axios({
            method: "get",
            url: `
            https://buy.vmall.com/queryQualification.json?activityID=${activityID}&sbomCode=${orders}&portal=1&rushTimestamp=${
              // res.data.data.rp
              11
            }&t=${new Date().getTime()}`,
            headers: {
              Accept: "application/json",
              "Accept-Encoding": "gzip, deflate, br, zstd",
              "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
              "Cache-Control": "no-store",
              Connection: "keep-alive",
              Cookie: Cookie[i],
            },
          }).then((res1) => {
            console.log(JSON.stringify(res1.data));
            if (res1.data.success) {
              console.log(
                "拿下！！！！！！！！！！！！！！！！！！！！！！！！！！！！"
              );
            }
          });
        }, 3000);
        // if (res.data.success) {
        //   clearInterval(timer);
        // }

        // debugger;
      })
      .catch((er) => {
        console.log(er);
      });
  }
};

let t = "2024-09-23 10:08:00"; //开始时间
let times = new Date(t).getTime();
console.log("目标时间戳", times);

/**
 *  2022-06-19T04:03:50.378Z  -500
    2022-06-19T04:05:50.743Z  -200
    2022-06-19T04:09:50.891Z  -100
    2022-06-19T04:07:11.282Z  
 
 */
let js = setInterval(() => {
  if (new Date().getTime() >= times - 300) {
    clearInterval(js);
    console.log("开始执行");
    console.log(new Date().getTime());
    init();
  }

  console.log(
    `目标时间:${t},当前时间${moment(new Date().getTime()).format(
      "YYYY-MM-DD HH:mm:ss"
    )}`
  );
}, 100);
